{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8b2111ae",
   "metadata": {},
   "source": [
    "# Basic Agents and Teams with Agno\n",
    "\n",
    "This example demonstrates the fundamentals of creating AI agents and organizing them into collaborative teams using the Agno framework.\n",
    "\n",
    "## Overview\n",
    "\n",
    "In this example, you'll learn how to:\n",
    "- **Create specialized AI agents** with specific roles and expertise\n",
    "- **Organize agents into teams** for collaborative problem-solving\n",
    "- **Use coordination modes** for effective agent communication\n",
    "- **Monitor agent interactions** with AgentOps integration\n",
    "\n",
    "## Key Concepts\n",
    "\n",
    "### Agents\n",
    "Individual AI entities with specific roles and capabilities. Each agent can be assigned a particular area of expertise, making them specialists in their domain.\n",
    "\n",
    "### Teams\n",
    "Collections of agents that work together to solve complex tasks. Teams can coordinate their responses, share information, and delegate tasks based on each agent's expertise.\n",
    "\n",
    "### Coordination Modes\n",
    "Different strategies for how agents within a team interact and collaborate. The \"coordinate\" mode enables intelligent task routing and information sharing."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d087e416",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Install the required dependencies\n",
    "%pip install agentops\n",
    "%pip install agno\n",
    "%pip install python-dotenv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "39ad00cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from dotenv import load_dotenv\n",
    "\n",
    "import agentops\n",
    "from agno.agent import Agent\n",
    "from agno.team import Team\n",
    "from agno.models.openai import OpenAIChat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f733e281",
   "metadata": {},
   "outputs": [],
   "source": [
    "load_dotenv()\n",
    "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\", \"your_openai_api_key_here\")\n",
    "os.environ[\"AGENTOPS_API_KEY\"] = os.getenv(\"AGENTOPS_API_KEY\", \"your_agentops_api_key_here\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb37819a",
   "metadata": {},
   "outputs": [],
   "source": [
    "agentops.init(auto_start_session=False, tags=[\"agno-example\", \"basics\", \"agents-and-teams\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e954b898",
   "metadata": {
    "vscode": {
     "languageId": "raw"
    }
   },
   "source": [
    "## Creating Agents and Teams\n",
    "\n",
    "Now let's create our specialized agents and organize them into a collaborative team:\n",
    "\n",
    "### Step 1: Create Individual Agents\n",
    "We'll create two agents with different specializations:\n",
    "- **News Agent**: Specializes in gathering and analyzing news\n",
    "- **Weather Agent**: Specializes in weather forecasting and analysis\n",
    "\n",
    "### Step 2: Form a Team\n",
    "We'll combine these agents into a team using the \"coordinate\" mode, which enables:\n",
    "- Intelligent task routing based on agent expertise\n",
    "- Information sharing between agents\n",
    "- Collaborative problem-solving\n",
    "\n",
    "### Step 3: Execute Tasks\n",
    "The team will automatically delegate tasks to the most appropriate agent(s) based on the query.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c12702d0",
   "metadata": {},
   "source": [
    "Here's the code to implement this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f872be2e",
   "metadata": {},
   "outputs": [],
   "source": [
    "def demonstrate_basic_agents():\n",
    "    \"\"\"\n",
    "    Demonstrate basic agent creation and team coordination.\n",
    "\n",
    "    This function shows how to:\n",
    "    1. Create specialized agents with specific roles\n",
    "    2. Organize agents into a team\n",
    "    3. Use the team to solve tasks that require multiple perspectives\n",
    "    \"\"\"\n",
    "    tracer = agentops.start_trace(\n",
    "        trace_name=\"Agno Basic Agents and Teams Demonstration\",\n",
    "    )\n",
    "\n",
    "    try:\n",
    "        # Create individual agents with specific roles\n",
    "        # Each agent has a name and a role that defines its expertise\n",
    "\n",
    "        # News Agent: Specializes in gathering and analyzing news information\n",
    "        news_agent = Agent(\n",
    "            name=\"News Agent\", role=\"Get the latest news and provide news analysis\", model=OpenAIChat(id=\"gpt-4o-mini\")\n",
    "        )\n",
    "\n",
    "        # Weather Agent: Specializes in weather forecasting and analysis\n",
    "        weather_agent = Agent(\n",
    "            name=\"Weather Agent\",\n",
    "            role=\"Get weather forecasts and provide weather analysis\",\n",
    "            model=OpenAIChat(id=\"gpt-4o-mini\"),\n",
    "        )\n",
    "\n",
    "        # Create a team with coordination mode\n",
    "        # The \"coordinate\" mode allows agents to work together and share information\n",
    "        team = Team(\n",
    "            name=\"News and Weather Team\",\n",
    "            mode=\"coordinate\",  # Agents will coordinate their responses\n",
    "            members=[news_agent, weather_agent],\n",
    "        )\n",
    "\n",
    "        # Run a task that requires team coordination\n",
    "        # The team will automatically determine which agent(s) should respond\n",
    "        response = team.run(\"What is the weather in Tokyo?\")\n",
    "\n",
    "        print(\"\\nTeam Response:\")\n",
    "        print(\"-\" * 60)\n",
    "        print(f\"{response.content}\")\n",
    "        print(\"-\" * 60)\n",
    "\n",
    "        agentops.end_trace(tracer, end_state=\"Success\")\n",
    "\n",
    "    except Exception as e:\n",
    "        print(f\"An error occurred: {e}\")\n",
    "        agentops.end_trace(tracer, end_state=\"Error\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca13c9b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "demonstrate_basic_agents()"
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "cell_metadata_filter": "-all",
   "main_language": "python",
   "notebook_metadata_filter": "-all"
  },
  "kernelspec": {
   "display_name": "agentops (3.11.11)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
